package w83b.w83bOperacionesPaso.w83bMantenimientos.w83bPlantillas;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import w83b.w83bBeans.W83bPlantillasBean;
import w83b.w83bUtilidades.W83bUtilidadesComunes;
import w83b.w83bUtilidadesComunes.W83bClsConstantes;
import es.ejie.frmk.presentacion.operacion.paso.Q70ActionPasoOP;
import es.ejie.frmk.presentacion.sesiondatos.Q70ContextoEJIE;


public class W83bTablaPlantillasOutOPAction extends Q70ActionPasoOP{

	
	protected void processOP(Q70ContextoEJIE contexto, ActionErrors errores, ActionMapping mapping,
			ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		
	}

	protected ActionForward processForward(Q70ContextoEJIE contexto, ActionErrors errors, ActionMapping mapping, 
			ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		W83bPlantillasBean bean = (W83bPlantillasBean)contexto.get("w83bPlantillasBean");
		int num_paginas = ((ArrayList)contexto.get("w83bListaPlantillas")).size()/Integer.parseInt(bean.getTotal());
		
		if(((ArrayList)contexto.get("w83bListaPlantillas")).size()%Integer.parseInt(bean.getTotal())>0){
			num_paginas++;
		}
		
		List listaVariables = new ArrayList();
		
		listaVariables.add("nombrePlantilla");
		String idioma = (String)contexto.get(W83bClsConstantes.CONSTANTE_CONTEXTO_IDIOMA);
		if(W83bClsConstantes.CONSTANTE_EUSKARA.equalsIgnoreCase(idioma)){
			listaVariables.add("descFaseEusk");
			listaVariables.add("descTramiteEusk");
			listaVariables.add("descripcion_eusk");
		}else{
			listaVariables.add("descFase");
			listaVariables.add("descTramite");
			listaVariables.add("descripcion");	
		}
		
		
		String varClave = "plantTramFase";
		
		bean.setRows(String.valueOf(num_paginas));
		
		
		
		String jJson = W83bUtilidadesComunes.procesarTabla((ArrayList)contexto.get("w83bListaPlantillas"),listaVariables,varClave,W83bPlantillasBean.class, bean);
		
		response.setContentType("text/javascript;charset=iso-8859-1");
		response.setHeader("Pragma", "cache");
		response.setHeader("Expires", "0");
		response.setHeader("Cache-Control", "private");
		response.setStatus(HttpServletResponse.SC_OK);
		PrintWriter out = response.getWriter();
		out.print(jJson);
		out.flush();
		
		return null;
	}
	


}
